<template>
    <div>
        <el-container class="form-container">
            <el-card class="box-card" shadow="never">
                <div slot="header" class="clearfix">
                    <span>${tableNameStr}</span>
                    <el-button type="primary" size="mini" style="float:right;padding: 6px 9px;" @click="submitForm">保存</el-button>
                </div>
                <div>
                    <el-form  :rules="rules"  ref="form" :label-position="labelPosition"  :model="form" size="small" label-width="120px">
                    <#list list as l>
                        <#if l_index%2==0>
                        <el-row>
                        </#if>
                        <el-col :span="12">
                            <el-form-item  label="${l.fdName}" <#if l.fdIsRequired>required</#if> prop="${l.fdModelName}">
                                <el-input class="input" v-model="form.${l.fdModelName}" <#if l.fdIsRequired>required</#if> ></el-input>
                            </el-form-item>
                        </el-col>
                        <#if l_index%2==1>
                        </el-row>
                        </#if>
                    </#list>
                    <#if list?size%2==1>
                        </el-row>
                    </#if>
                    </el-form>
                </div>
            </el-card>
        </el-container>
    </div>
</template>
<script>
import dateUtils from '@/utils/dateUtils';
import formUtils from '@/utils/formUtils';
export default {
    name: "${modelName}Edit",
    components: {
    },
    data() {
        return {
            form: {
                <#list list as l>
                ${l.fdModelName}:''<#if (l_has_next)>,</#if>
                </#list>
            },
            rules:{
            <#list list as l>
                <#if l.fdIsRequired>
                ${l.fdModelName} :[{required: true, message: '请输入${l.fdName}', trigger: 'blur'}]<#if (l_has_next)>,</#if>
                </#if>
            </#list>
	        },
            labelPosition:'right',
        }
    },
    created() {
        this.initParam();
    },
    methods: {
        submitForm() {
            this.$refs['form'].validate((valid) => {
                if (valid) {
                    this.fullscreenLoading = true;
                    let forms = formUtils.convertToModel(this.form);
                    this.$put('/api/${modulePath?replace(".","/")}/${tableName}',forms).then((res) => {
                        this.fullscreenLoading = false;
                        if(res.status==1){
                            this.$message({
                                message: res.message,
                                type: 'success',
                                onClose:()=>{
                                    this.$common.closeTag();
                                }
                            });
                        }else{
                            this.$message.error(res.message);
                        }
                    });

                }
            });
        },
        initParam() {
            let fdId = this.$route.query.id;
            if(formUtils.isNotEmpty(fdId)){
                this.fullscreenLoading = true;
                this.$fetch('/api/${modulePath?replace(".","/")}/${tableName}',{
                    id:fdId
                }).then((res) => {
                    formUtils.convertToForm(res.data,this.form);
                });
            }
        }
    }
}
</script>
<style scoped >
@import "~@/assets/css/form.css";
</style>